﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using SuperJ.Web.Areas.Admin.Models;
namespace SuperJ.Web.Areas.Admin.Controllers
{
    public class AnnounceController : Controller
    {
        // GET: Admin/Announce
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult List()
        {
            var context = new SuperJ.Web.Areas.Admin.Models.SuperJLiveEntities();
            List<SuperJ.Web.Areas.Admin.Models.Announce> announces = context.Announce.ToList<SuperJ.Web.Areas.Admin.Models.Announce>();
            //List<SuperJ.Web.Areas.Admin.Models.Announce> announces = context.Announce.Select(p => new
            //var announces = context.Announce.Select(p => new //SuperJ.Web.Areas.Admin.Models.Announce
            //{
            //    AnnounceID = p.AnnounceID,
            //    Title = p.Title,
            //    FullContent = p.FullContent,
            //    CreateTime = p.CreateTime
            //}).ToList<SuperJ.Web.Areas.Admin.Models.Announce>();
            return View(announces);
        }
        // GET: Admin/Announce/Details/5
        public ActionResult Details(int id)
        {
            return View();
        }

        // GET: Admin/Announce/Create
        public ActionResult Form()
        {
            
            return View();
        }
        [HttpPost]
        public ActionResult Form(Announce a)
        {
            using (SuperJLiveEntities context = new SuperJLiveEntities())
            {
                Announce announce = new Announce();
                announce.Title = a.Title;
                announce.FullContent = a.FullContent;
                announce.CreateTime = DateTime.Now;
                context.Announce.Add(announce);
                context.SaveChanges();
            }
            return View();
        }
        // POST: Admin/Announce/Create
        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        // GET: Admin/Announce/Edit/5
        public ActionResult Edit(int id)
        {
            return View();
        }

        // POST: Admin/Announce/Edit/5
        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        // GET: Admin/Announce/Delete/5
        public ActionResult Delete(int id)
        {
            return View();
        }

        // POST: Admin/Announce/Delete/5
        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
